"""
Celery 应用配置
"""

from celery import Celery
from app.config import Config

# 创建Celery应用实例
celery_app = Celery(
    'md2dockit',
    broker=Config.REDIS_URL,
    backend=Config.REDIS_URL,
    include=['md2dockit.app.tasks']
)

# Celery配置
celery_app.conf.update(
    # 任务序列化
    task_serializer='json',
    accept_content=['json'],
    result_serializer='json',
    
    # 时区设置
    timezone='Asia/Shanghai',
    enable_utc=True,
    
    # 任务路由
    task_routes={
        'md2dockit.app.tasks.convert_document': {'queue': 'conversion'},
        'md2dockit.app.tasks.cleanup_files': {'queue': 'cleanup'},
    },
    
    # 任务配置
    task_always_eager=False,
    task_eager_propagates=True,
    task_ignore_result=False,
    task_store_eager_result=True,
    
    # 结果过期时间（秒）
    result_expires=3600,
    
    # 任务超时时间（秒）
    task_soft_time_limit=300,
    task_time_limit=600,
    
    # 工作进程配置
    worker_prefetch_multiplier=1,
    worker_max_tasks_per_child=1000,
    
    # 监控配置
    worker_send_task_events=True,
    task_send_sent_event=True,
    
    # 队列配置
    task_default_queue='default',
    task_default_exchange='default',
    task_default_exchange_type='direct',
    task_default_routing_key='default',
    
    # 重试配置
    task_acks_late=True,
    task_reject_on_worker_lost=True,
)